//
//  QYGAccountInputView.m
//  wawaji_ios
//
//  Created by 奇艺果 on 2018/1/15.
//  Copyright © 2018年 yiguo qi. All rights reserved.
//

#import "QYGAccountInputView.h"

@interface QYGAccountInputView()
@property (strong, nonatomic) UITextField *accountField;
@property (strong, nonatomic) UITextField *psdField;
@property (strong, nonatomic) UIButton *loginBtn;
@property (strong, nonatomic) UIImageView *accountImgView;
@property (strong, nonatomic) UIImageView *psdImgView;
@property (strong, nonatomic) UIView *topLine;
@property (strong, nonatomic) UIView *bottomLine;

@end

@implementation QYGAccountInputView
+ (instancetype)accountInputView{
    return nil;
}

- (void)loginBtnClick{
    
    if(NULLString(self.accountField.text) || NULLString(self.psdField.text)){
        [self makeToast:@"请输入账号密码!"];
        return;
    }
    if(self.loginBlock){
        self.loginBlock(self.accountField.text, self.psdField.text);
    }
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self setupUI];
    }
    return self;
}
- (void)setupUI{
    
    [self addSubview:self.accountImgView];
    [self addSubview:self.psdImgView];
    [self addSubview:self.accountField];
    [self addSubview:self.psdField];
    [self addSubview:self.topLine];
    [self addSubview:self.bottomLine];
    [self addSubview:self.loginBtn];
    
    [self.accountImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top).offset(20);
        make.width.equalTo(@13);
        make.height.equalTo(@15);
    }];
    
    [self.psdImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.accountImgView).offset(ScaleW(40));
        make.width.equalTo(@13);
        make.height.equalTo(@15);
    }];
    
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.accountImgView.mas_top);
        make.bottom.equalTo(self.psdImgView.mas_bottom).offset(10);
        make.width.equalTo(@70);
    }];
    [self.accountField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.accountImgView.mas_centerY);
        make.left.equalTo(self.accountImgView.mas_right).offset(20);
        make.right.equalTo(self.loginBtn.mas_left).offset(-20);
    }];
    
    [self.psdField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.psdImgView.mas_centerY);
        make.left.equalTo(self.accountField.mas_left);
        make.right.equalTo(self.accountField.mas_right);
    }];
    
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.accountField.mas_right);
        make.top.equalTo(self.accountField.mas_bottom).offset(ScaleW(8));
        make.height.equalTo(@1);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.accountField.mas_right);
        make.top.equalTo(self.psdField.mas_bottom).offset(ScaleW(8));
        make.height.equalTo(@1);
    }];
}
- (UIButton *)loginBtn{
    if(!_loginBtn){
        _loginBtn = [UIButton buttonWithTitle:@"登录" setTitleColor:[UIColor whiteColor] setTitleFont:ScaleFont(17) setState:UIControlStateNormal];
        [_loginBtn viewWithcornerRadius:10 borderWidth:0 borderColor:nil backgroundColor:[UIColor colorWithHex:@"09bb07"]];
        [_loginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
        }
    return _loginBtn;
}
- (UIView *)bottomLine{
    if(!_bottomLine){
        _bottomLine = [[UIView alloc] init];
        _bottomLine.backgroundColor = [UIColor colorWithHex:@"e4e3e8"];
    }
    return _bottomLine;
}
- (UIView *)topLine{
    if(!_topLine){
        _topLine = [[UIView alloc] init];
        _topLine.backgroundColor = [UIColor colorWithHex:@"e4e3e8"];
    }
    return _topLine;
}
- (UITextField *)psdField{
    if(!_psdField){
        _psdField = [[UITextField alloc] init];
        _psdField.placeholder = @"密码";
        _psdField.font = ScaleFont(17);
        _psdField.textColor = [UIColor colorWithHex:@"999999"];
        _psdField.keyboardType = UIKeyboardTypeNumberPad;
    }
    return _psdField;
}
- (UITextField *)accountField{
    if(!_accountField){
        _accountField = [[UITextField alloc] init];
        _accountField.placeholder = @"账号";
        _accountField.textColor = [UIColor colorWithHex:@"999999"];
        _accountField.font = ScaleFont(17);
        _accountField.keyboardType = UIKeyboardTypeNumberPad;
    }
    return _accountField;
}
- (UIImageView *)psdImgView{
    if(!_psdImgView){
        _psdImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lock"]];
        [_psdImgView sizeToFit];
    }
    return _psdImgView;
}
- (UIImageView *)accountImgView{
    if(!_accountImgView){
        _accountImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user"]];
        
        [_accountImgView sizeToFit];
    }
    return _accountImgView;
}
@end
